#include<bits/stdc++.h>
using namespace std;
#define int long long

struct node {
	int val, index;
} a[1000005];

signed main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		int x = i;
		a[i] = {0, i};
		while (x) {
			a[i].val += x % 10;
			x /= 10;
		}
	}
	sort(a + 1, a + n + 1, [](node x, node y) {
		if (x.val != y.val)
			return x.val < y.val;
		else
			return x.index < y.index;
	});
	cout << a[m].index;
	return 0;
}
